package hanqi.busline.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import hanqi.busline.Line;
import hanqi.busline.mapper.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class BusLineServiceImpl implements BusLineService {
    @Autowired
    private Mapper mapper;
    @Override
    public List<Line> getallBusLine() {
        return mapper.selectList(null);
    }
    @Override
    public void insertBusLine(Line line) {
mapper.insert(line);
    }
    @Override
    public void deleteBusLineByid(Integer id) {
mapper.deleteById(id);
    }

    @Override
    public void updateBusLine(Line line) {
        mapper.updateById(line);


    }
    @Override
    public Line getBusLineById(Integer id) {
        return  mapper.selectById(id);

    }

    @Override
    public List<Line> getBusLineByName(String name) {
        QueryWrapper<Line> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("firststation", name).or().eq("laststation", name);
        return mapper.selectList(queryWrapper);
    }
    /* LambdaQueryChainWrapper<Line> wrapper=new LambdaQueryChainWrapper<Line>(Line.class)
                .select(Line::getId,Line::getFirststation,Line::getLaststation)
                .like(Line::getFirststation,name);
               // .like(Line::getLaststation,name);


       return mapper.selectList(wrapper);*/
}
